import 'package:flutter/material.dart';

class NestedPage extends StatefulWidget {
  const NestedPage({Key key}) : super(key: key);

  @override
  _NestedPageState createState() => _NestedPageState();
}

class _NestedPageState extends State<NestedPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              title: Text('Flutter Demo'),
              floating: true,
              pinned: true,
              snap: true,
              expandedHeight: 200,
              flexibleSpace: FlexibleSpaceBar(
                background: Image.network(
                  'https://www.itying.com/images/flutter/1.png',
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ];
        },
        body: Stack(alignment: Alignment.bottomCenter, children: [
          PageView(
            children: <Widget>[
              Container(
                color: Colors.red,
                child: Center(
                  child: Text('Page 1'),
                ),
              ),
              Container(
                color: Colors.blue,
                child: Center(
                  child: Text('Page 2'),
                ),
              ),
              Container(
                color: Colors.green,
                child: Center(
                  child: Text('Page 3'),
                ),
              ),
            ],
          ),
          //指示器
          Positioned(
            bottom: 10,
            child: Row(
                children: List.generate(3, (index) {
              return Container(
                margin: EdgeInsets.all(10),
                width: 10,
                height: 10,
                decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    color: 1 == index ? Colors.amberAccent : Colors.white),
              );
            }).toList()),
          ),
        ]),
      ),
    );
  }
}
